package com.dkm.ec.product.domain;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.dkm.base.api.service.IdGenerator;
import com.dkm.base.core.helper.SpringHelper;
import com.dkm.biz.domain.AbstractDomain;
import com.dkm.biz.gl.persistence.dao.GlCateQueryDao;
import com.dkm.ec.product.persistence.dao.ProdCateDao;
import com.dkm.ec.product.persistence.entity.ProdCatePo;

/**
 * 对象功能:产品从属分类表 领域对象实体
 * 开发公司:SKG.COM
 * 开发人员:HJD
 * 创建时间:2015-07-20 11:37:18
 */
@SuppressWarnings("serial")
@Service
@Scope("prototype")
public class ProdCate extends AbstractDomain<String, ProdCatePo>{
	 @ Resource
	 private ProdCateDao prodCateDao ;
	 @Resource
	 private GlCateQueryDao glCateQueryDao;
	 private IdGenerator idGenerator = SpringHelper.getBean(IdGenerator.class);

	protected void init(){
		prodCateDao = SpringHelper.getBean(ProdCateDao.class);
		setDao(prodCateDao);
	}	 
	
	/**
	 * 保存产品对应的类型(保存之前删除该产品所有分类)
	 * @param prodCatePos
	 * @param prodId
	 */
	public  void  saveProdCateWithProdId(List<ProdCatePo> prodCatePos ,String prodId){
		if(prodCatePos!=null && prodCatePos.size()>0 && prodId!=null){
			for(ProdCatePo prodCatePo:prodCatePos){
				prodCatePo.setId(idGenerator.genSid());
				prodCatePo.setProdId(prodId);
				prodCatePo.setCreateTime(new Date());
			}
			prodCateDao.deleteByProdId(prodId);
			prodCateDao.batchInsert(prodCatePos);
		}
//		return proList;
	}
	
	
	
	
}
